<%@ include file="/common/taglibs.jsp"%>

<head>
    <title><fmt:message key="supplierDetail.title"/></title>
    <meta name="heading" content="<fmt:message key='supplierDetail.heading'/>"/>
    <meta name="menu" content="MaterialMenu"/>
    <script type="text/javascript">
        dojo.event.topic.subscribe("/save", function(data, type, request) {
            if(type == "load") {
                dojo.byId("phoneIndex").value = "";
                dojo.byId("phoneIndex1").value = "";
                dojo.byId("phoneId").value = "";
                dojo.byId("phoneType").value = "";
                dojo.byId("phoneNumber").value = "";
                dojo.byId("phoneIdPerson").value = "";

                document.getElementById('deletePhoneForm').style.display = 'none';

                $('addPhoneButton').appear();
                Effect.SlideUp('divPhoneForm');
                return false;
            }
        });
        function editPhone(row){
            dojo.byId("phoneIndex").value = row.rowIndex - 1;
            dojo.byId("phoneIndex1").value = row.rowIndex - 1;

            var tds = row.getElementsByTagName("td");

            dojo.byId("phoneId").value = dojo.string.trim(dojo.dom.textContent(tds[0]));
            dojo.byId("phoneType").value = dojo.string.trim(dojo.dom.textContent(tds[1]));
            dojo.byId("phoneNumber").value = dojo.string.trim(dojo.dom.textContent(tds[2]));
            dojo.byId("phoneIdPerson").value = dojo.string.trim(dojo.dom.textContent(tds[3]));

            document.getElementById('deletePhoneForm').style.display = 'inline';

            $('addPhoneButton').fade();
            Effect.SlideDown('divPhoneForm');
            return false;
        }
    </script>
</head>

    <s:form id="supplierForm" action="saveSupplier" method="post" >
        <s:hidden name="supplier.id" value="%{supplier.id}"/>
  <s:textfield key="supplier.name" required="true" cssClass="text semilarge"/>
        <s:textfield key="supplier.razonSocial" required="true" cssClass="text semilarge"/>
        <s:textfield key="supplier.address" required="true" cssClass="text semilarge"/>
        <s:textfield key="supplier.nit" cssClass="text medium"/>
  <s:textfield key="supplier.phone1" cssClass="text medium"/>
  <s:textfield key="supplier.phone2" cssClass="text medium"/>

        <li class="buttonBar bottom">
            <s:submit cssClass="button" method="save" key="button.save" theme="simple"/>
            <c:if test="${not empty supplier.id}">
                <s:submit cssClass="button" method="delete" key="button.delete" onclick="return confirmDelete('supplier')" theme="simple"/>
            </c:if>
            <s:submit cssClass="button" method="cancel" key="button.cancel" theme="simple"/>
        </li>
    </s:form>
<script type="text/javascript">
    Form.focusFirstElement($("supplierForm"));

    document.getElementById('divPhone').style.top = document.getElementById('supplierForm').offsetTop+"px";
</script>